﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using mvcPractice.Entity;
using mvcPractice.Service;


namespace mvcPractice.Controllers
{
    [Route("api/[controller]")]
    public class TransferController : Controller
    {
        private readonly TransferService _service;
        public TransferController(TransferService service)
        {
            _service = service;
        }

        // GetStationById
        [HttpGet(Name = "GetStation")]
        public Object GetStation([FromQuery]int stationId)
        {
            Console.WriteLine("ok");
            var ob = _service.GetStation(stationId);
            Console.WriteLine(ob);
            return _service.GetStation(stationId);
        }

        // PostAutoStation
        [HttpPost("addStation")]
        public IActionResult PostAutoStation([FromBody]AutoStation station)
        {
            Console.WriteLine(station);
            if (station == null)
            {
                return BadRequest();
            }
            _service.AddStation(station);
            return CreatedAtRoute("GetStation", new { stationId = station.Id });
        }

        // Update AutoStation
        [HttpPut("updateStation")]
        public IActionResult Put([FromBody]AutoStation station)
        {
            var item = _service.UpdateStation(station);
            return CreatedAtRoute("GetStation", new { stationId = station.Id });
        }

        // DELETE AutoStation by Id
        [HttpDelete("delStation/{id}")]
        public void Delete(int id)
        {
            _service.DelStation(id);
        }

        // GET test
        [HttpGet("test")]
        public IEnumerable<string> Get()
        {
            _service.linqtest();
            return new string[] { "value1", "value2" };
        }
    }
}
